package com.base.controller;


import cn.dev33.satoken.util.SaResult;
import com.base.entity.Student;
import com.base.entity.TestData;
import com.base.service.IStudentService;
import com.base.service.ITestDataService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 作者
 * @since 2024-08-20
 */
@RestController
@RequestMapping("/test-data")
@Api(tags = "测试数据")
@CrossOrigin
public class TestDataController {

    @Autowired
    private ITestDataService testDataService;

    @ApiOperation("列表")
    @GetMapping("/list")
    public List<TestData> getList() {
        return testDataService.list();
    }

    @ApiOperation("更新")
    @PostMapping
    public SaResult update(@RequestBody TestData testData) {
        if (testData.getId() == null) {
//            新增
            testData.setCreatedAt(LocalDateTime.now());
            testDataService.save(testData);
        } else {
//            编辑
            testDataService.updateById(testData);
        }
        return SaResult.ok();
    }

    @ApiOperation("移除")
    @GetMapping("/remove/{id}")
    public SaResult remove(@PathVariable Integer id) {
        testDataService.removeById(id);
        return SaResult.ok();
    }

}
